package com.jzo2o.foundations.controller.consumer;

import com.jzo2o.foundations.model.dto.response.HotServeVO;
import com.jzo2o.foundations.model.dto.response.ServeCategoryResDTO;
import com.jzo2o.foundations.model.dto.response.ServeSimpleResDTO;
import com.jzo2o.foundations.model.dto.response.ServeTypeResDTO;
import com.jzo2o.foundations.service.HomeService;
import com.jzo2o.foundations.service.ServeAggregationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * @author itlxc
 * @since 2024-10-16
 */
@Validated
@RestController("consumerServeController")
@RequestMapping("/customer/serve")
@Api(tags = "用户端 - 首页服务查询接口")
@Slf4j
@RequiredArgsConstructor
public class FirstPageServeController {

    private final HomeService homeService;

    private final ServeAggregationService serveAggregationService;

    @GetMapping("/firstPageServeList")
    @ApiOperation("首页服务列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "regionId", value = "区域id", required = true, dataTypeClass = Long.class)
    })
    public List<ServeCategoryResDTO> serveCategory(@RequestParam("regionId") Long regionId) {
        log.info("查询首页服务列表：{}", regionId);
        return homeService.queryServeIconCategoryByRegionIdCache(regionId);
    }

    @GetMapping("/serveTypeList")
    @ApiOperation("服务分类列表")
    public List<ServeCategoryResDTO> serveTypeList(@RequestParam("regionId") Long regionId) {
        log.info("查询服务分类列表：{}", regionId);
        return homeService.queryServeTypeList(regionId);
    }

    @GetMapping("/hotServeList")
    @ApiOperation("热门服务列表")
    public List<HotServeVO> hotServeList(@RequestParam("regionId") Long regionId) {
        log.info("查询热门服务列表：{}", regionId);
        return homeService.queryHotServeList(regionId);
    }

    @GetMapping("/{id}")
    @ApiOperation("查看服务详情")
    public HotServeVO serveDetail(@PathVariable("id") Long id) {
        log.info("查看服务详情：{}", id);
        return homeService.getServeDetail(id);
    }

    @GetMapping("/search")
    @ApiOperation("首页服务搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cityCode", value = "城市编码", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(name = "serveTypeId", value = "服务类型id", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "keyword", value = "关键词", dataTypeClass = String.class)
    })
    public List<ServeSimpleResDTO> findServeList(@RequestParam("cityCode") String cityCode,
                                                 @RequestParam(value = "serveTypeId", required = false) Long serveTypeId,
                                                 @RequestParam(value = "keyword", required = false) String keyword) throws IOException {
        log.info("首页服务搜索：{},{},{}", cityCode, serveTypeId, keyword);
        return serveAggregationService.findServeList(cityCode, serveTypeId, keyword);
    }
}
